﻿<%@ page pageEncoding="UTF-8"%>
<%@ taglib prefix="isperp" uri="/WEB-INF/tlds/isperp.tld"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>

<script type="text/javascript">
	function departmentTree_onNodeClick(event, treeId, treeNode) {
		// alert(treeNode.treenodePath);
		//alert(	JSON.stringify(treeNode));

		deptmentUserGrid.search({
			"field" : "department_treenode_path",
			"op" : "bw",
			"data" : treeNode.treenodePath
		});
	}

	function createDepartment() {

		var node = departmentTree.zTree.getSelectedNode();
		if (node == undefined) {
			isperp.alert("请先选择一个部门！");
			return false;
		}

		var options = {
			title : "新增子部门",
			contentUrl : "app/department/edit?parentId=" + node.id
		};
		isperp.showDialog(options);
	}

	function updateDepartment() {

		var node = departmentTree.zTree.getSelectedNode();
		if (node == undefined) {
			isperp.alert("请先选择一个部门！");
			return false;
		}

		var options = {
			title : "新增子部门",
			contentUrl : "app/department/edit?id=" + node.id
		};
		isperp.showDialog(options);

	}

	function restUserPassword() {
		var row = deptmentUserGrid.getRowData();
		if (!row) {
			isperp.alert("请选择一条用户数据！");
			return;
		}
		isperp.confirmAlert("您确定要重置用户【" + row.fullname + "】的密码为 123456 吗？", {
			yes : function() {
				$.post("app/user/restPassword/" + row.id, function() {
					isperp.tooltip("用户【" + row.fullname + "】密码已经重置为：123456！");
				});
			}
		});

	}

	function getDomain() {
		var nodes = departmentTree.zTree.getSelectedNodes();

		if (!nodes || nodes.length == 0) {
			return true;
		}

		var treeNode = nodes[0];
		var dn = treeNode.treenodeNamePath, domainValue = "";

		if (dn.indexOf("DLR") > -1) {
			if (!treeNode.leaf) {
				alert("请选择DLR下的叶子节点");
				return false;
			}
			domainValue = "DLR";
		} else if (dn.indexOf("汽车有限公司") > -1) {
			domainValue = "GTMCL";
		} else if (dn.indexOf("合作伙伴") > -1) {
			domainValue = "SUP";
			if (treeNode.name != "IT供应商" && dn.indexOf("IT供应商") > -1) {
				return "deptId=" + treeNode.id;
			} else if (!treeNode.leaf) {
				alert("请选择供应商");
				return false;
			}
		}
		return "deptId=" + treeNode.id;
	}

	var checkAddNode = function(treeId, treeNode) {
		var dn = treeNode.treenodeNamePath, domainValue = "";

		if (dn.indexOf("合作伙伴") > -1) {
			return true;
		}
		return false;
	};
</script>
<div id="dvFrameMainNav" class="frame-main-nav">
	<isperp:tree id="departmentTree" modal="false"
		cusCreateUrl="app/department/edit"
		beforeAddHoverDomeFun="checkAddNode">
		<isperp:async enable="true" autoParam="'id'"
			otherParam="{asyncLoad:1}" url="app/department/getTree">
		</isperp:async>
		<isperp:callback onClick="departmentTree_onNodeClick">
		</isperp:callback>

		<isperp:edit enable="true" showRemoveBtn="false" showRenameBtn="false"></isperp:edit>
		<isperp:view showTitle="false" addHoverDom="true" nameIsHTML="true"
			removeHoverDom="true"></isperp:view>
	</isperp:tree>
</div>
<section id="mainContent" class="frame-main-cont frame-main-cont-first"
	role="main">
	<div id="dvContainer">
		<isperp:grid gridId="deptmentUserGrid" url="app/user/deptmentUser"
			gridTitle="人员" pager="userPager" cusFormatterActions="true"
			cusEditUrl="app/user/edit" cusDialogSize="big"
			sortname="code" autoReloadTreeMenu="userMenu"
			ondbClickRowEvent="deptmentUserGrid.edit(rowid);" actionsWidth="70"
			beforeCreateAction="getDomain();" cusDeleteUrl="app/user/delete"
			excelExportUrl="app/user/excelExport">
			<jsp:attribute name="toolbar">
				<isperp:treeMenu id="userMenu" targetGridId="deptmentUserGrid">
						<isperp:async enable="true" url="app/user/userStatusMenu"></isperp:async>
						<isperp:callback onClick="userMenuTree_onNodeClick"
						onAsyncSuccess="userMenuTree_onNodeClickFirst();">
						</isperp:callback>
				</isperp:treeMenu>
			
				<isperp:toolbar id="userToolbar">
				    <!--114是供应商窗口数据级别-->
                   
					<isperp:button id="userCreate" icon="icon-plus" text="新增人员"
							cssClass="nui-mainbtn" onclick="deptmentUserGrid.create();"></isperp:button>
					<isperp:button icon="icon-cog" text="重置密码"
							onclick="restUserPassword();"></isperp:button>
					
						
					<%-- <isperp:button id="userEdit" icon="icon-download" text="导出到Excel"
						onclick="deptmentUserGrid.excelExport();"></isperp:button> --%>
				</isperp:toolbar>
				</jsp:attribute>

			<jsp:attribute name="searchbar">
				<table class="search-table">
					<tbody>
						<tr style="height:40px;">
								<td align="right">关键字：</td>
								<td align="left"><input type="text" style="width:180px;"
								field="name,fullname,email,mobile,position,tel,memo"
								op="cn"> (可按姓名、邮件、职务、手机、电话、备注查询)
								</td>
								
							</tr>
					</tbody>
				</table>
				</jsp:attribute>
			<jsp:body>	
				<isperp:column name="id" title="id" hidden="true"></isperp:column>

				<isperp:column name="gender" title="性别" width="50" hidden="true">
				</isperp:column>
				<isperp:column name="" title="姓名" isFormatterFun="true"
					formatter="return nameFormatter(rowObject.fullname,rowObject.gender);"
					width="90">
				</isperp:column>
				<isperp:column name="fullname" title="姓名" hidden="true" width="50">
				</isperp:column>
				<isperp:column name="name" title="用户帐号" width="90">
				</isperp:column>
				<isperp:column name="code" title="工号" width="70">
				</isperp:column>
				<isperp:column name="position" title="职务" width="60">
				</isperp:column>
				<isperp:column name="mobile" title="移动电话" width="80">
				</isperp:column>
				<isperp:column name="tel" title="座机电话" width="80">
				</isperp:column>
				<isperp:column name="email" title="邮箱" width="90">
				</isperp:column>
				<isperp:column name="duty" title="班值" width="90">
				</isperp:column>
				<isperp:column name="department_name" title="所在部门" width="100">
				</isperp:column>
				
                <isperp:column name="data_source" title="来源" width="60">
				</isperp:column>
				<isperp:column name="enable" title="有效" width="60"
					isFormatterFun="true"
					formatter="return isperp.statusFormatter(cellvalue);">
				</isperp:column> 
				</jsp:body>

		</isperp:grid>
		<isperp:operate code="ORG_EMPLOYEE"></isperp:operate>
	</div>
</section>



<script type="text/javascript">
	function nameFormatter(cellvalue, gender) {
		if (gender == '男')
			return "<img src='img/icons/packs/fugue/24x24/user-business.png'>" + cellvalue;
		else
			return "<img src='img/icons/packs/fugue/24x24/user-female.png'>" + cellvalue;

	}
</script>



<style>
<!--
.fixed {
	position: fixed;
}

#dvFrameMainNav {
	overflow: auto
}
-->
</style>
<script type="text/javascript">
	var getScrollY = function() {
		scrOfY = 0;
		if (typeof (window.pageYOffset) == "number") {
			scrOfY = window.pageYOffset;
		} else if (document.body && (document.body.scrollLeft || document.body.scrollTop)) {
			scrOfY = document.body.scrollTop;
		} else if (document.documentElement && (document.documentElement.scrollLeft || document.documentElement.scrollTop)) {
			scrOfY = document.documentElement.scrollTop;
		}
		return scrOfY;

	}

	var pos_fixed_start_y = 120;
	var pos_fixed_stop_y = $(document).height() - $(window).height() - 150;
	$(window).scroll(function() {

		var y = getScrollY();

		if (y == 0) {
			$("#dvFrameMainNav").css({
				height : 'auto'
			});
		}
		var nav = $('#dvFrameMainNav');
		if (y >= pos_fixed_start_y && y <= pos_fixed_stop_y) {
			nav.addClass('fixed');
			resetTagTreeHeight();
		} else if (y > pos_fixed_stop_y) {
			nav.addClass('fixed');
			resetTagTreeHeight2();
		} else {
			nav.removeClass('fixed');
		}
	});

	var resetTagTreeHeight = function() {
		var tt = $("#dvFrameMainNav");
		var height = $(window).height();
		tt.css({
			height : height - 20
		});
	};

	var resetTagTreeHeight2 = function() {
		var tt = $("#dvFrameMainNav");
		var height = $(window).height();
		tt.css({
			height : height - 20
		});
	};

	resetTagTreeHeight2();
</script>

